// 获取服务器数据
async function fuwuqi() {
   const data= await axios({url:'http://cba.itlike.com/public/index.php?s=/api/category/list'})
  //  console.log(data)
  //  console.log(data.data.data.list)
   const list=data.data.data.list
   console.log(list)

   document.querySelector('.left ul').innerHTML=list.map(function (item,index) { 
     return `<li><a href="javascript:;" data-id="${index}">${item.name}</a></li>`
   }).join('')
// 首屏渲染 
document.querySelector('.left ul a').classList.add('active')
document.querySelector('.right ul').innerHTML=list[0].children.map(function (item) {
   return `<li>
   <img src=${item.image.external_url} alt="">
   <p>${item.name}</p>
 </li>`
}).join('')

// 点击事件
   document.querySelector('.left ul').addEventListener('click',function (e) {
     if (e.target.tagName==='A') {
      const active=document.querySelector('.left .active')
      if (active) {
        active.classList.remove('active')
      }
         e.target.classList.add('active')

if (list[e.target.dataset.id].children) {
  document.querySelector('.right ul').innerHTML=list[e.target.dataset.id].children.map(function (item) {
    return `<li>
    <img src=${item.image.external_url} alt="">
    <p>${item.name}</p>
  </li>`
  }).join('')
// 点击右边大盒子跳转到商品列表
  document.querySelectorAll('.right li').forEach(function (item) {
    item.addEventListener('click',function () {
      location.href='../智慧商城 销售列表/智慧商城商品列表.html'
    })
 })
}else{document.querySelector('.right ul').innerHTML=''}

     }
   })
 // 给底部导航设置点击跳转----事件委托
 document.querySelector('.footer ul').addEventListener('click', function (e) {
  if (e.target.tagName == 'LI' || e.target.tagName == 'SPAN' || e.target.tagName == 'P') {
    if (e.target.dataset.id == 1) {
      location.href = "../智慧商城（首页）/智慧商城.html"
    }
    if (e.target.dataset.id == 3) {
      location.href = "../智慧商城购物车/index.html"
    }
    if (e.target.dataset.id == 4) {
      location.href = "../个人中心/个人中心.html"
    }
  }
})




















}
fuwuqi()
